﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Base;
using Base.Core;
using AonesoftBase.Biz;
using AonesoftBase;
using System.IO;
public partial class CreatePurchase_htm : Base.BasePage
{
    // Methods
    private string bind(int id)
    {
        int num = 0x1388;
        int num2 = 1;
        string str = "1";
        string str2 = "";
        string str3 = "";
        char ch = '0';
        char ch2 = '1';
        StringBuilder builder = new StringBuilder();
        string strSelect = " top " + num + " ";
        if (str == "1")
        {
            strSelect = strSelect + " C_Purchase.ID as ID ,Name";
        }
        else
        {
            strSelect = strSelect + " C_Supply.ID as ID , Name";
        }
        if (ch2 == '1')
        {
            strSelect = strSelect + " , AddDate";
        }
        if ((ch == '1') && (str != "1"))
        {
            strSelect = strSelect + ",Type ";
        }
        string strTableName = "";
        if (str == "1")
        {
            strTableName = "C_Purchase";
        }
        else
        {
            strTableName = "C_Supply";
        }
        if ((ch == '1') && (str != "1"))
        {
            strTableName = strTableName + " , W_IndustryType";
        }
        if (str == "1")
        {
            strTableName = strTableName + " , U_userInfo";
        }
        StringBuilder builder2 = new StringBuilder();
        builder2.Append("where 1=1  ");
        builder2.Append(string.Format("and C_Purchase.UserID = U_userInfo.UserID and C_Purchase.verify='1' and id between {0} and {1} ", (id - 1) * 0x1388, id * 0x1388));
        if ((str2.ToString().Length > 0) && (str2.ToString() != "0"))
        {
            builder2.Append(" and patindex('%," + str2 + ",%' , ','+IndType+',')>0 ");
        }
        if (str3 != "")
        {
            if (str3 == "0")
            {
                builder2.Append("and Recommend = 'False' ");
            }
            else
            {
                builder2.Append("and Recommend = 'True' ");
            }
        }
        string strOrder = "order by AddDate desc";
        DataTable table = nspLable.Function.Function.GetDataTable(strSelect, builder2.ToString(), strTableName, strOrder);
        if (table.Rows.Count <= 0)
        {
            return "暂无该信息";
        }
        string webURL = new WebConfig().WebURL;
        int count = table.Rows.Count;
        num = count;
        int num4 = num2;
        int num5 = ((count % num4) == 0) ? (count / num4) : ((count / num4) + 1);
        builder.Append(string.Concat(new object[] { "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>求购、采购信息！我要销售上久易扶持网求购大全－第", (id - 1) * 0x1388, "～", id * 0x1388, "条求购信息，商机不可错过</title><meta content=\"求购大全，久易扶持网,求购,求购信息,采购会,大买家,买家,求购频道,紧急求购,求购网,网上采购,求购热点\" name=\"keywords\" /><meta content=\"久易扶持网求购大全（www.wansogu.cn）--求购商家众多，让您足不出户成交生意。这里是商人销售产品、拓展市场及网络推广的首选网站。\" name=\"description\" /><link rel=\"stylesheet\" href=\"", webURL, "Templates/blue/skins/default/websen.css\" /><link rel=\"stylesheet\" href=\"", webURL, "Templates/blue/skins/default/index.css\" /></head>" }));
        builder.Append(string.Concat(new object[] { "<body><center></br><h1>第", (id - 1) * 0x1388, "～", id * 0x1388, "条求购信息</h1></center><br/>" }));
        builder.Append("<table width='100%'  border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
        for (int i = 0; i < num5; i++)
        {
            for (int j = 0; j < num4; j++)
            {
                builder.Append("<tr><td>\n ");
                int num8 = (i * num4) + j;
                if ((num8 > (count - 1)) || (num8 > num))
                {
                    break;
                }
                builder.Append("<a href=\"");
                if (str == "0")
                {
                    builder.Append(webURL + "Supply/Detail-");
                }
                else
                {
                    builder.Append(webURL + "Purchase/Detail-");
                }
                builder.Append(table.Rows[num8]["ID"].ToString() + BasePage.Config.Rewrite);
                builder.Append("\" target=_blank>");
                builder.Append(table.Rows[num8]["name"].ToString() + "&nbsp;&nbsp;");
                builder.Append(table.Rows[num8]["AddDate"].ToString());
                builder.Append("</a>\n ");
                builder.Append("</td></tr>");
            }
        }
        builder.Append("</table></body></html>");
        return builder.ToString();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        BasePage.CheckRights("column", "A1");
        if (!base.IsPostBack)
        {
            BaseCommon common = new BaseCommon(DBcommon.DBConn);
            decimal d = decimal.Parse(common.GetMax("id", "C_Purchase").ToString()) / 5000M;
            int num3 = int.Parse(Math.Ceiling(d).ToString());
            string webURL = new WebConfig().WebURL;
            StringBuilder builder = new StringBuilder();
            builder.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>求购、采购信息！我要销售上久易扶持网求购大全，商机不可错过</title><meta content=\"求购大全，久易扶持网,求购,求购信息,采购会,大买家,买家,求购频道,紧急求购,求购网,网上采购,求购热点\" name=\"keywords\" /><meta content=\"久易扶持网求购大全（www.wansogu.cn）--求购商家众多，让您足不出户成交生意。这里是商人销售产品、拓展市场及网络推广的首选网站。\" name=\"description\" /><link rel=\"stylesheet\" href=\"" + webURL + "Templates/blue/skins/default/websen.css\" /><link rel=\"stylesheet\" href=\"" + webURL + "Templates/blue/skins/default/index.css\" /></head>");
            builder.Append("<body>");
            for (int i = 1; i <= num3; i++)
            {
                string filename = string.Format("Pur{0}-{1}", i - 1, i);
                builder.Append(string.Concat(new object[] { "<a href=\"", webURL, "more/pur/", filename, ".htm\" target=_blank>第", i }));
                builder.Append("页</a>&nbsp;>>&nbsp;");
                WriteFile(this.bind(i), filename);
            }
            builder.Append("</body></html>");
            WriteFile(builder.ToString(), "index");
            base.Response.Write("求购静态页生成成功！&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:history.go(-1);'>返回</a>");
        }
    }

    public static bool WriteFile(string str, string filename)
    {
        string path = AppDomain.CurrentDomain.BaseDirectory.ToString() + @"more\pur\" + filename + ".htm";
        Encoding encoding = Encoding.GetEncoding("UTF-8");
        StreamWriter writer = null;
        try
        {
            writer = new StreamWriter(path, false, encoding);
            writer.Write(str);
            writer.Flush();
        }
        catch (Exception exception)
        {
            HttpContext.Current.Response.Write(exception.Message);
            HttpContext.Current.Response.End();
        }
        finally
        {
            writer.Close();
        }
        return true;
    }

    }